
// import Hls from 'hls.js'

export function comjs(app) {
	
	 
	
	var AudioContext = uni.createInnerAudioContext()
	console.log(AudioContext)
	app.config.globalProperties.voice1=(src,refs,that)=>{
		
		var	videoContext = uni.createVideoContext('audioId')
		// videoContext.play();
		// console.log(videoContext,"kjjj")
		console.log(1111,that)
		console.log(2222,refs)
		setTimeout(()=>{
			console.log(',,,',refs)
			refs.src="https://video.chaojidanci.com/205e5391d0c571f08aae6723a78f0102/98e6ef583daf34d7de239fa0899ab920-fd-m3u8-encrypt-stream.m3u8?auth_key=1733468082-7d0be17cb4844f248bf262215589b2a2-0-c2a106cd0ecbbd55693d5e224213586e"
			console.log(refs.src)
			videoContext.play();
			
		},1000)
		
		
		return
		
		if(src){
			app.config.globalProperties.httpimg([src],2).then(res=>{
				console.log(refs.src)
				
				
				
				// if (Hls.isSupported()) {
				// 		let hls = new Hls();
				// 		hls.loadSource(res.data[0].fileUrl);
				// 		hls.attachMedia(refs);
				// 		hls.on(Hls.Events.MANIFEST_PARSED, () => {
				// 		  console.log("视频加载成功");
				// 		  refs.play();
				// 		});
				//  }
				
			})
		}
		
		// AudioContext.stop()
		
		// if(src){
		// 	AudioContext.src = src;
		// 	AudioContext.play()
		// }else{
		// 	uni.showToast({duration: 2000,
		// 		title:'还没有',
		// 		icon:"none"
		// 	})
		// }
		
	}
	
	app.config.globalProperties.customer=()=>{
		// #ifdef MP-WEIXIN
			wx.openCustomerServiceChat({
			  extInfo: {url: 'https://work.weixin.qq.com/kfid/kfc15c6e21ab9e44e18'},
			  corpId: 'ww6b54ef025790d93b',
			  success(res) {
			  },
			  fail(res) {
			  },
			})
		// #endif
		// #ifdef H5
		location.href='https://work.weixin.qq.com/kfid/kfc15c6e21ab9e44e18'
		// #endif
	}
	
	app.config.globalProperties.wreplace = (str,res,color) =>{
			const regex = new RegExp(`(${str})`, 'gi');
			if(color){
				return res.replace(
					regex, 
					'<text style="color:#303133;">$1</text>'
				);
			}else{
				return res.replace(
					regex, 
					'<text style="color:red;">$1</text>'
				);
			}
	}
	
	app.config.globalProperties.nodata = (res,that) =>{
		if(res.length){
			that.isdata = false
		}else{
			that.isdata = true
		}
	}
	app.config.globalProperties.toast=(text)=>{
		 uni.showToast({duration: 2000,
			title:text,
			icon:"none"
		})
	}
	
	app.config.globalProperties.upimg = (count)=> {
		return new Promise((resolve, reject) => {
		  uni.chooseImage({
		    count: count ? count : 9,
		    success: (res) => {
		      uni.showLoading({
		        mask: true,
		      });
		      var image = res.tempFilePaths;
		      var ff = [];
		      for (let i = 0; i < image.length; i++) {
				  console.log(image[i])
		        uni.uploadFile({
		          url: 	uni.getStorageSync('upimg')+'/api/upload/image',
		          filePath: image[i],
		          name: 'file',
		          header: {
		            Authorization: uni.getStorageSync('token'),
		          },
		          success: (uploadFileRes) => {
		            ff.push(JSON.parse(uploadFileRes.data).data.data.url);
					if(ff.length ==  image.length){
						resolve(ff);
						uni.hideLoading()
					}
		          },
		          fail(e) {
		            uni.hideLoading();
		            uni.showModal({
		              content: '网络错误,稍后再试',
		            });
		          },
		        });
		      }
		    },
		  });
		});
		
		
		uni.chooseImage({
			count: 1,
			success: (res) => {
				uni.showLoading({
					mask: true
				}) 
			
				uni.uploadFile({
						url: uni.getStorageSync('upimg') + 'user/headimg',
						filePath: res.tempFilePaths[0],
						name: 'file',
							header: {
								Authorization: uni.getStorageSync('token')
							},
						success: (uploadRes) => {
						  		uni.showToast({duration: 2000,
						  			title: "修改成功",
						  			icon: "none"
						  		})
						  		setTimeout(() => {
						  			this.getUserInfo()
						  		}, 700)
						  		uni.hideLoading()
						  
						},
						fail: (err) => {
						 		uni.hideLoading()
						 		uni.showModal({
						 			content: "网络错误,稍后再试"
						 		})
						}
				});
			 
			}, 
			fail:(res)=> {
				console.log(22222)
				console.log(res)
			}
		})
	
	}
	 
 
	app.config.globalProperties.qidai=()=>{
		uni.showToast({duration: 2000,
			title:"敬请期待",
			icon:"none"
		})
	}
	app.config.globalProperties.thistime = () => {
		 
		 const now = new Date();
		 const year = now.getFullYear();
		 const month = now.getMonth() + 1;
		 const day = now.getDate();
		 const hour = now.getHours();
		 const minute = now.getMinutes();
		 const second = now.getSeconds();
		return year+'/'+month+'/'+ day +' '  +hour +':'+ minute +':'+second
	}
	

	
 

	app.config.globalProperties.navto=(url)=>{
		uni.navigateTo({
			url
		})
	}
	// #ifdef H5
	  app.config.globalProperties.shh = 30
	  app.config.globalProperties.bhh = 20
	// #endif
	
	
	
	
	// #ifdef MP-WEIXIN
	  app.config.globalProperties.shh = uni.getSystemInfoSync().statusBarHeight+5
	  app.config.globalProperties.bhh = uni.getSystemInfoSync().safeAreaInsets.bottom+10
	// #endif
	
	
	app.config.globalProperties.istime = (time,newsp) => {
		if (time) {	
			var times = time.replace(/-/g, '/');
			// var newtime = newsp.replace(/-/g, '/');
			if (new Date(times).getTime() - new Date().getTime() > 0) {
				return true //没到
			} else {
				return false
			}
		}
		
	}
	app.config.globalProperties.copy = (copy)=>{
		uni.setClipboardData({
			data: copy,
			success: function () {
				uni.showToast({duration: 2000,
					title: '复制成功',
					icon: 'none',
				});
			}
		})
	}
	app.config.globalProperties.hao = (number) => {
	  number = number + ''
	  var ac = number.length == 1 ? '0000' + number : number.length == 2 ? '000' + number : number.length == 3 ? '00' +
	  	number : number.length == 4 ? '0' + number : number
	   return ac
	},
	app.config.globalProperties.back = () => {
		if (getCurrentPages().length == 1) {
			uni.reLaunch({
				url: "/pages/index/index"
			})
		} else {
			uni.navigateBack()
		}
	}

}
